/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bungabungaball.player;

import bungabungaball.GlobalSettings;
import bungabungaball.PlayerControl;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.World;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;

/**
 * A player that is controlled by a network client.
 * 
 * @author Ingo Klose, Stephan Meyer, Sebastian Lehmann
 * @version 1.0
 */
public class Network extends Player {

     /**
     * The server IP
     */
    private static String serverIp;

    /**
     *
     * @param s
     */
    public static void setServerIp(String s) {
        serverIp = s;
    }

    /**
     * draw the player
     * @param g
     */
    @Override
    public void draw(Graphics g) {
        g.drawImage(image, x, y);
    }

    /**
     * Constructor
     * @param x
     * @param y
     * @param image
     * @param w
     */
    public Network(int x, int y, Image image, World w) {
        super(x, y, image, w);
        init();
    }

    /**
     * Move the player
     * @param pc
     * @param delta
     * @param body
     * @param keyMapClientPlayer 
     */
    @Override
    public void move(PlayerControl pc, int delta, Body body, boolean[] keyMapClientPlayer) {
        if (keyMapClientPlayer != null) {
            if (keyMapClientPlayer[0]) {
                this.rotate(-this.rotation * delta);
            }
            if (keyMapClientPlayer[1]) {
                this.rotate(this.rotation * delta);
            }
            if (!keyMapClientPlayer[2] && !keyMapClientPlayer[3]) {
                makeFriction(body);
            }
            if (keyMapClientPlayer[2]) {
                float hip = this.speed * delta;
                double speedRotation = Math.toRadians(this.getRotation() - 90.f);
                Vec2 force = new Vec2((float) (hip * Math.cos(speedRotation)), (float) (hip * Math.sin(speedRotation)));
                //body2.setLinearVelocity(force);
                
                if (controlMode == GlobalSettings.ControlMode.Normal) {
                    body.setLinearVelocity(force);
                } else {
                    body.applyLinearImpulse(force, body.getWorldCenter());
                }
            }
            if (keyMapClientPlayer[3]) {
                float hip = this.speed * delta;
                double speedRotation = Math.toRadians(this.getRotation() - 90.f);
                Vec2 force = new Vec2(-(float) (hip * Math.cos(speedRotation)), -(float) (hip * Math.sin(speedRotation)));
                //body2.setLinearVelocity(force);

                if (controlMode == GlobalSettings.ControlMode.Normal) {
                    body.setLinearVelocity(force);
                } else {
                    body.applyLinearImpulse(force, body.getWorldCenter());
                }
            }
        }
    }
}
